﻿namespace Jsl.FxCop
{
    using System;
    using System.Windows.Forms;
    using Microsoft.FxCop.Sdk;
    using Microsoft.VisualStudio.TestTools.UnitTesting;

    [TestClass]
    public class TestRemoveEmptyEventHandlers
    {
        [TestMethod]
        public void Finds_standard_event_handlers()
        {
            new RemoveEmptyEventHandlers()
                .RunMethodRule(
                    () =>
                    {
                        Control control = new Control();
                        control.TextChanged += this.EmptyHandler;
                    })
                .HasProblem(
                    90,
                    FixCategories.NonBreaking,
                    MessageLevel.Warning,
                    "Remove the empty event handler.")
                .HasNoMoreProblems();
        }

        //// The rule doesn't find anonymous event handlers. Consider rewriting using visitors.
        //[TestMethod]
        //public void Finds_anonymous_event_handlers()
        //{
        //    var problems = RuleHelper.RunMethodRule(
        //        new RemoveEmptyEventHandlers(),
        //        () =>
        //        {
        //            Control control = new Control();
        //            control.TextChanged += (sender, e) =>
        //            {
        //                // Empty event handler.
        //            };
        //        });

        //    Assert.AreEqual(1, problems.Count);
        //}

        #region Private Methods
        private void EmptyHandler(object sender, EventArgs e)
        {
            // Empty event handler.
        }
        #endregion Private Methods
    }
}
